package com.time.company.components.login;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.Spannable;
import android.widget.TextView;

import com.time.company.R;
import com.time.company.base.BaseActivity;
import com.time.company.components.MainActivity;
import com.time.company.utils.SpanFormatter;

import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by Bing on 2017/11/8.
 * E-mail is tx16bing@163.com
 */

public class CommitSCActivity extends BaseActivity{

    private static final String EXTRA_ACCOUNT = "extra_account";
    private static final String EXTRA_PASSWORD = "extra_password";
    private static final String EXTRA_REGISTER_AWARD = "extra_register_award";

    private TextView tvLoginInfo, tvTip;

    public static void start(Activity activity, String account, String psd, String regAward) {
        Intent intent = new Intent(activity, CommitSCActivity.class);
        intent.putExtra(EXTRA_ACCOUNT, account);
        intent.putExtra(EXTRA_PASSWORD, psd);
        intent.putExtra(EXTRA_REGISTER_AWARD, regAward);
        activity.startActivity(intent);
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_commit_sc);

        tvLoginInfo = findView(R.id.tv_commit_sc_login_info);
        tvTip = findView(R.id.tv_commit_sc_tip);
        tvLoginInfo.setText(String.format(
                getString(R.string.commit_sc_login_info),
                getIntent().getStringExtra(EXTRA_ACCOUNT),
                getIntent().getStringExtra(EXTRA_PASSWORD)));
        Spannable meStr = SpanFormatter.getColoredSpannable(this, "我的", R.color.colorThirdPrimary);
        tvTip.setText(SpanFormatter.format(getString(R.string.commit_sc_tip), meStr));

        Timer timer = new Timer();
        TimerTask timerTask = new TimerTask() {
            @Override
            public void run() {
                MainActivity.start(CommitSCActivity.this);
            }
        };
        timer.schedule(timerTask, 5000);
    }
}
